package o;

import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class akb extends ajh {
    private static final Pattern ˎ = Pattern.compile("(?:(\\d+):)?(\\d+):(\\d+)(?::|\\.)(\\d+)");
    private int ʻ;
    private final boolean ˊ;
    private int ˋ;
    private int ˏ;
    private int ॱ;

    protected /* synthetic */ aji ˎ(byte[] bArr, int i, boolean z) throws SubtitleDecoderException {
        return ˊ(bArr, i, z);
    }

    public akb() {
        this(null);
    }

    public akb(List<byte[]> list) {
        super("SsaDecoder");
        if (list == null || list.isEmpty()) {
            this.ˊ = false;
            return;
        }
        this.ˊ = true;
        String ॱ = anr.ॱ((byte[]) list.get(0));
        amm.ˊ(ॱ.startsWith("Format: "));
        ˏ(ॱ);
        ॱ(new anc((byte[]) list.get(1)));
    }

    protected akc ˊ(byte[] bArr, int i, boolean z) {
        List arrayList = new ArrayList();
        amv o_amv = new amv();
        anc o_anc = new anc(bArr, i);
        if (!this.ˊ) {
            ॱ(o_anc);
        }
        ˋ(o_anc, arrayList, o_amv);
        Cue[] cueArr = new Cue[arrayList.size()];
        arrayList.toArray(cueArr);
        return new akc(cueArr, o_amv.ˏ());
    }

    private void ॱ(anc o_anc) {
        String ˊˋ;
        do {
            ˊˋ = o_anc.ˊˋ();
            if (ˊˋ == null) {
                return;
            }
        } while (!ˊˋ.startsWith("[Events]"));
    }

    private void ˋ(anc o_anc, List<Cue> list, amv o_amv) {
        while (true) {
            String ˊˋ = o_anc.ˊˋ();
            if (ˊˋ == null) {
                return;
            }
            if (!this.ˊ && ˊˋ.startsWith("Format: ")) {
                ˏ(ˊˋ);
            } else if (ˊˋ.startsWith("Dialogue: ")) {
                ˋ(ˊˋ, (List) list, o_amv);
            }
        }
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private void ˏ(java.lang.String r7) {
        /*
        r6 = this;
        r1 = 0;
        r3 = -1;
        r0 = "Format: ";
        r0 = r0.length();
        r0 = r7.substring(r0);
        r2 = ",";
        r4 = android.text.TextUtils.split(r0, r2);
        r0 = r4.length;
        r6.ॱ = r0;
        r6.ˋ = r3;
        r6.ˏ = r3;
        r6.ʻ = r3;
        r0 = r1;
    L_0x001c:
        r2 = r6.ॱ;
        if (r0 >= r2) goto L_0x005f;
    L_0x0020:
        r2 = r4[r0];
        r2 = r2.trim();
        r2 = o.anr.ˎ(r2);
        r5 = r2.hashCode();
        switch(r5) {
            case 100571: goto L_0x0042;
            case 3556653: goto L_0x004c;
            case 109757538: goto L_0x0038;
            default: goto L_0x0031;
        };
    L_0x0031:
        r2 = r3;
    L_0x0032:
        switch(r2) {
            case 0: goto L_0x0056;
            case 1: goto L_0x0059;
            case 2: goto L_0x005c;
            default: goto L_0x0035;
        };
    L_0x0035:
        r0 = r0 + 1;
        goto L_0x001c;
    L_0x0038:
        r5 = "start";
        r2 = r2.equals(r5);
        if (r2 == 0) goto L_0x0031;
    L_0x0040:
        r2 = r1;
        goto L_0x0032;
    L_0x0042:
        r5 = "end";
        r2 = r2.equals(r5);
        if (r2 == 0) goto L_0x0031;
    L_0x004a:
        r2 = 1;
        goto L_0x0032;
    L_0x004c:
        r5 = "text";
        r2 = r2.equals(r5);
        if (r2 == 0) goto L_0x0031;
    L_0x0054:
        r2 = 2;
        goto L_0x0032;
    L_0x0056:
        r6.ˋ = r0;
        goto L_0x0035;
    L_0x0059:
        r6.ˏ = r0;
        goto L_0x0035;
    L_0x005c:
        r6.ʻ = r0;
        goto L_0x0035;
    L_0x005f:
        r0 = r6.ˋ;
        if (r0 == r3) goto L_0x006b;
    L_0x0063:
        r0 = r6.ˏ;
        if (r0 == r3) goto L_0x006b;
    L_0x0067:
        r0 = r6.ʻ;
        if (r0 != r3) goto L_0x006d;
    L_0x006b:
        r6.ॱ = r1;
    L_0x006d:
        return;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.akb.ˏ(java.lang.String):void");
    }

    private void ˋ(String str, List<Cue> list, amv o_amv) {
        if (this.ॱ == 0) {
            amz.ˏ("SsaDecoder", "Skipping dialogue line before complete format: " + str);
            return;
        }
        String[] split = str.substring("Dialogue: ".length()).split(",", this.ॱ);
        if (split.length != this.ॱ) {
            amz.ˏ("SsaDecoder", "Skipping dialogue line with fewer columns than format: " + str);
            return;
        }
        long ˋ = ˋ(split[this.ˋ]);
        if (ˋ == -9223372036854775807L) {
            amz.ˏ("SsaDecoder", "Skipping invalid timing: " + str);
            return;
        }
        long j;
        String str2 = split[this.ˏ];
        if (str2.trim().isEmpty()) {
            j = -9223372036854775807L;
        } else {
            j = ˋ(str2);
            if (j == -9223372036854775807L) {
                amz.ˏ("SsaDecoder", "Skipping invalid timing: " + str);
                return;
            }
        }
        list.add(new Cue(split[this.ʻ].replaceAll("\\{.*?\\}", "").replaceAll("\\\\N", "\n").replaceAll("\\\\n", "\n")));
        o_amv.ˋ(ˋ);
        if (j != -9223372036854775807L) {
            list.add(null);
            o_amv.ˋ(j);
        }
    }

    public static long ˋ(String str) {
        Matcher matcher = ˎ.matcher(str);
        if (!matcher.matches()) {
            return -9223372036854775807L;
        }
        return (Long.parseLong(matcher.group(4)) * 10000) + (((((Long.parseLong(matcher.group(1)) * 60) * 60) * 1000000) + ((Long.parseLong(matcher.group(2)) * 60) * 1000000)) + (Long.parseLong(matcher.group(3)) * 1000000));
    }
}
